/*
 * @Description: 部门接收审核上下文
 * @Author: Rfan
 * @Date: 2022-05-19 17:28:35
 * @LastEditTime: 2022-05-19 17:49:02
 */

import { createContext, useContext, useEffect, useReducer } from 'react';
import { ReceivingReviewReducer } from '../reducers/ReceivingReviewReducer';
import { SET_SELECT_FOND } from '../constants';

const initialState = {
  // 当前选中的项目
  selectUnit: {},
  selectFond: {},
  selectAT: {},
  selectLevel: {},
  // 选中的表格条目
  selectItems: []
};

const ReceivingReviewContext = createContext();

const ReceivingReviewContextProvider = (props) => {
  const [state, dispatch] = useReducer(ReceivingReviewReducer, initialState);

  const actions = {
    /**
     * @description: 设置选中的全宗
     */
    setSelectFond(data) {
      dispatch({ type: SET_SELECT_FOND, data });
    }
  };

  // watch listQuery来加载排序列表
  useEffect(() => {}, []);

  return (
    <ReceivingReviewContext.Provider value={{ ...state, ...actions }}>
      {props.children}
    </ReceivingReviewContext.Provider>
  );
};

export const useReceivingReviewContext = () => {
  return useContext(ReceivingReviewContext);
};

export { ReceivingReviewContext, ReceivingReviewContextProvider };
